/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003-2012 Steffen Nissen (sn@leenissen.dk)

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <stdio.h>

#include "fann.h"

int FANN_API test_callback(struct fann *ann, struct fann_train_data *train,
	unsigned int max_epochs, unsigned int epochs_between_reports,
	float desired_error, unsigned int epochs)
{
	printf("Epochs     %8d. MSE: %.5f. Desired-MSE: %.5f\n", epochs, fann_get_MSE(ann), desired_error);
	return 0;
}
int main(int argc, char *argv[])
{
	const char* extIn = ".tenet";
	const int mse_error = 0;
	const int bit_error = 1;

	if (argc <4)
	{
		printf("0\nBadNumberOfParams");
		return 0;
	}

	char* baseNetwork = argv[1];
	char* trainingFile = argv[2];
	int error_type = atoi(argv[3]);

	struct fann *ann;

	char* sourceIn = (char *)malloc(1 + strlen(extIn) + strlen(baseNetwork));
	strcpy(sourceIn, baseNetwork);
	strcat(sourceIn, extIn);
	

	ann = fann_create_from_file(sourceIn);
	struct fann_train_data *data;
	data = fann_read_train_from_file(trainingFile);

	float error;
	fann_reset_MSE(ann);
	fann_test_data(ann, data);
	
	if (error_type == mse_error)
	{
		error = fann_get_MSE(ann);
	}
	else if (error_type == bit_error)
	{
		error = fann_get_bit_fail(ann);
	}
	 

	printf("1\n%f", error);
	fann_destroy(ann);
	fann_destroy_train(data);
	
	return 0;
}
